<?php
declare (strict_types=1);

namespace app\admin\traits;

/**
 * 数据仓库公共方法
 * Trait RepositoryTrait
 * @package app\traits
 */
trait RepositoryTrait
{
    /**
     * @param $id
     * @param array $field
     * @param bool $where
     * @return mixed
     */
    public static function getInfoByID($id, $field = [], $where = true)
    {
        return self::$model::where([self::$pk => $id])->where($where)->field($field ?: self::$model::$showField)->find();
    }
    /**
     * 通过name获取信息
     */
    public static function getInfoByName($name, $field = [], $where = true)
    {
        return self::$model::where([self::$name => $name])->where($where)->field($field ?: self::$model::$showField)->find();
    }

    /**
     * 新增
     * @param $data
     */
    public static function add($data)
    {
        return self::$model::create($data);
    }
    /**
     * 编辑
     * @param $id
     * @param $data
     */
    public static function edit($id, $data)
    {

    }
}